/*
* create by lixy 20150628
* Just for DMap(tuteng) Project
* copyright@ 2015
*/
"use strict";

!function(a) {
	a.app.service('highchartsService', [function () {

        var theme = {
        		colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
        		 		"#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
        		 	chart: {
        		 		backgroundColor: null,
        		 		style: {
        		 			fontFamily: "Dosis, sans-serif"
        		 		}
        		 	},
        		 	title: {
        		 		style: {
        		 			fontSize: '16px',
        		 			fontWeight: 'bold',
        		 			textTransform: 'uppercase'
        		 		}
        		 	},
        		 	tooltip: {
        		 		borderWidth: 0,
        		 		backgroundColor: 'rgba(219,219,216,0.8)',
        		 		shadow: false
        		 	},
        		 	legend: {
        		 		itemStyle: {
        		 			fontWeight: 'bold',
        		 			fontSize: '13px'
        		 		}
        		 	},
        		 	xAxis: {
        		 		gridLineWidth: 1,
        		 		labels: {
        		 			style: {
        		 				fontSize: '12px'
        		 			}
        		 		}
        		 	},
        		 	yAxis: {
        		 		minorTickInterval: 'auto',
        		 		title: {
        		 			style: {
        		 				textTransform: 'uppercase'
        		 			}
        		 		},
        		 		labels: {
        		 			style: {
        		 				fontSize: '12px'
        		 			}
        		 		}
        		 	},
        		 	plotOptions: {
        		 		candlestick: {
        		 			lineColor: '#404048'
        		 		}
        		 	},
        		 	// General
        		 	background2: '#F0F0EA'
        		 };

        /**
         * 绘制趋势图
         * title	标题
         * cate		曲线分类
         * series	序列
         */
        this.drawLine = function(id,title,cate,series) {
        	Highcharts.setOptions(theme);// Apply the theme
        	$('#'+id).highcharts({
                title: {
                    text: title,
                    x: -20 //center
                },
                subtitle: {
                    text: '参考',
                    x: -20
                },
                xAxis: {
                    categories: cate
                },
                yAxis: {
                    title: {
                        text: 'Cpu (core * min)'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: series
            });
        }

        /**
         * 绘制饼图
         */
        this.drawPie = function (id,title,data) {
        	Highcharts.setOptions(theme);// Apply the theme
        	$(function(){
        		$('#'+id).highcharts({
        	        chart: {
        	            plotBackgroundColor: null,
        	            plotBorderWidth: null,
        	            plotShadow: false
        	        },
        	        title: {
        	            text: title
        	        },
        	        tooltip: {
        	    	    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        	        },
        	        plotOptions: {
        	            pie: {
        	                allowPointSelect: true,
        	                cursor: 'pointer',
        	                dataLabels: {
        	                    enabled: true,
        	                    color: '#000000',
        	                    connectorColor: '#000000',
        	                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
        	                }
        	            }
        	        },
        	        series: [{
        	            type: 'pie',
        	            data: data
        	        }]
        	    });
        	});
        }

    }]);
    
}(this);
